package org.csu.group4.jpetstore.controller;

import org.csu.group4.jpetstore.mybatis.entity.Item;
import org.csu.group4.jpetstore.mybatis.entity.Product;
import org.csu.group4.jpetstore.result.Result;
import org.csu.group4.jpetstore.result.ResultFactory;
import org.csu.group4.jpetstore.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import org.csu.group4.jpetstore.service.ItemService;

import java.util.List;


@Controller
public class CommonController {

    @Autowired
    ItemService itemService;

    @Autowired
    ProductService productService;

    @GetMapping(value = "/")
    public String getIndex(){
        return "index";
    }
    @ResponseBody
    @GetMapping(value = "/help")
    public String getHelp(){
        return "<a>HELP<a>";
    }

    @PostMapping(value = "/common/Search")
    public String Search(String keyword,Model model){
        List<Product> products = productService.SearchProduct("%"+keyword+"%");

        model.addAttribute("product",products);

        return "/catalog/SearchProducts";
    }
}
